home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / GDIMETA.PAK / TOOLBAR.C < prev    next >
C/C++ Source or Header  |  1997-05-06  |  6KB  |  158 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE: toolbar.c
  9. //
  10. //  PURPOSE: Handles general routines for the Toolbar control
  11. //
  12. //  FUNCTIONS:
  13. //    CreateTBar    - Creates the Toolbar control for the sample.
  14. //    MsgNotify     - Handles the WM_NOTIFY message that gets sent to
  15. //                    the parent window to get ToolTip Text.
  16. //  COMMENTS:
  17. //
  18.  
  19. #include <windows.h>            // required for all Windows applications
  20. #include <windowsx.h>
  21. #include <commctrl.h>           // prototypes and defs for common controls
  22. #include "globals.h"            // prototypes specific to this application
  23. #include "resource.h"
  24. #include "toolbar.h"            // prototypes and #defines for toolbar.c
  25.  
  26. // Global Variable for the toolbar control.
  27.  
  28. HWND    hWndToolbar;
  29.  
  30. //  **TODO**  Change the following values to match your toolbar bitmap
  31. //
  32. // NUMIMAGES    = Number of images in toolbar.bmp.  Note that this is not
  33. //                the same as the number of elements on the toolbar.
  34. // IMAGEWIDTH   = Width of a single button image in toolbar.bmp
  35. // IMAGEHEIGHT  = Height of a single button image in toolbar.bmp
  36. // BUTTONWIDTH  = Width of a button on the toolbar (zero = default)
  37. // BUTTONHEIGHT = Height of a button on the toolbar (zero = default)
  38.  
  39. #define NUMIMAGES       18
  40. #define IMAGEWIDTH      18
  41. #define IMAGEHEIGHT     17
  42. #define BUTTONWIDTH     0
  43. #define BUTTONHEIGHT    0
  44.  
  45. //  **TODO**  Add/remove entries in the following array to define the 
  46. //            toolbar buttons (see documentation for TBBUTTON).
  47.  
  48. TBBUTTON tbButton[] =           // Array defining the toolbar buttons
  49.  
  50.     // the struct goes like this:
  51.     // bitmap index, WM_COMMAND id, state, style, reserved bytes, app data,
  52.     // string index
  53.     // Note that the reserved bytes exist only for Win32 targets
  54. {
  55.      { 0, IDM_FILENEW,     TBSTATE_ENABLED,       TBSTYLE_BUTTON, {0, 0}, 0, 0},
  56.      { 1, IDM_FILEOPEN,    TBSTATE_ENABLED,       TBSTYLE_BUTTON, {0, 0}, 0, 0},
  57.      { 2, IDM_FILESAVE,    TBSTATE_ENABLED,       TBSTYLE_BUTTON, {0, 0}, 0, 0},
  58.      { 6, IDM_FILEPRINT,   TBSTATE_INDETERMINATE, TBSTYLE_BUTTON, {0, 0}, 0, 0},
  59.      { 0, 0,               TBSTATE_ENABLED,       TBSTYLE_SEP,    {0, 0}, 0, 0},
  60. //    { 3, IDM_EDITCUT,     TBSTATE_ENABLED,     TBSTYLE_BUTTON, {0, 0}, 0, 0},
  61. //    { 4, IDM_EDITCOPY,    TBSTATE_ENABLED,     TBSTYLE_BUTTON, {0, 0}, 0, 0},
  62. //    { 5, IDM_EDITPASTE,   TBSTATE_ENABLED,     TBSTYLE_BUTTON, {0, 0}, 0, 0},
  63. //    { 0, 0,               TBSTATE_ENABLED,     TBSTYLE_SEP,    {0, 0}, 0, 0},
  64.      { 9, IDM_PIXEL,       TBSTATE_ENABLED,    TBSTYLE_CHECKGROUP, {0, 0}, 0, 0},
  65.      {10, IDM_LINE,        TBSTATE_ENABLED,    TBSTYLE_CHECKGROUP, {0, 0}, 0, 0},
  66.      {11, IDM_RECT,        TBSTATE_ENABLED,    TBSTYLE_CHECKGROUP, {0, 0}, 0, 0},
  67.      {12, IDM_ELLIPSE,     TBSTATE_ENABLED,    TBSTYLE_CHECKGROUP, {0, 0}, 0, 0},
  68.      {13, IDM_BEZIER,      TBSTATE_ENABLED,    TBSTYLE_CHECKGROUP, {0, 0}, 0, 0},
  69.      { 0, 0,               TBSTATE_ENABLED,    TBSTYLE_SEP,        {0, 0}, 0, 0},
  70.      {14, IDM_FILL,        TBSTATE_ENABLED,    TBSTYLE_CHECKGROUP, {0, 0}, 0, 0},
  71.      {15, IDM_NOFILL,      TBSTATE_ENABLED,    TBSTYLE_CHECKGROUP, {0, 0}, 0, 0},
  72.      { 0, 0,               TBSTATE_ENABLED,    TBSTYLE_SEP,        {0, 0}, 0, 0},
  73.      {16, IDM_CREATEPEN,   TBSTATE_ENABLED,    TBSTYLE_BUTTON,     {0, 0}, 0, 0},
  74.      {17, IDM_CREATEBRUSH, TBSTATE_ENABLED,    TBSTYLE_BUTTON,     {0, 0}, 0, 0},
  75.      { 0, 0,               TBSTATE_ENABLED,    TBSTYLE_SEP,        {0, 0}, 0, 0},
  76.      { 7, IDM_ABOUT,       TBSTATE_ENABLED,    TBSTYLE_BUTTON,     {0, 0}, 0, 0},
  77. };
  78.  
  79.  
  80. //
  81. //  FUNCTION: CreateTBar(HWND)
  82. //
  83. //  PURPOSE:  Calls CreateToolBarEx()
  84. //
  85. //
  86. //  PARAMETERS:
  87. //
  88. //  hwnd - Window handle : Used for the hWndParent parameter of the control.
  89. //
  90. //  RETURN VALUE:
  91. //
  92. //  If toolbar control was created successfully Return TRUE,
  93. //  else returns FALSE.
  94. //
  95. //  COMMENTS:
  96. //
  97. //
  98.  
  99. BOOL CreateTBar(HWND hwnd)
  100. {
  101.     hWndToolbar = CreateToolbarEx(hwnd,
  102.                                   WS_CHILD | WS_VISIBLE | TBSTYLE_TOOLTIPS,
  103.                                   IDM_TOOLBAR,
  104.                                   NUMIMAGES,
  105.                                   hInst,
  106.                                   IDB_BMP,
  107.                                   tbButton,
  108.                                   sizeof(tbButton)/sizeof(TBBUTTON),
  109.                                   BUTTONWIDTH,
  110.                                   BUTTONHEIGHT,
  111.                                   IMAGEWIDTH,
  112.                                   IMAGEHEIGHT,
  113.                                   sizeof(TBBUTTON));
  114.  
  115.     return (hWndToolbar != NULL);
  116. }
  117.  
  118. //
  119. //  FUNCTION: MsgNotify(HWND, UINT, WPARAM, LPARAM)
  120. //
  121. //  PURPOSE:  WM_NOTIFY is sent to the parent window to get the
  122. //            tooltip text assoc'd with that toolbar button.
  123. //
  124. //  PARAMETERS:
  125. //
  126. //    hwnd      - Window handle  (Unused)
  127. //    uMessage  - Message number (Unused)
  128. //    wparam    - Extra data     (Unused)
  129. //    lparam    - TOOLTIPTEXT FAR*
  130. //
  131. //  RETURN VALUE:
  132. //    Always returns 0 - Message handled
  133. //
  134. //
  135. //  COMMENTS:
  136. //    This message fills in the lpszText field of the TOOLTIPTEXT
  137. //    structure if code == TTN_NEEDTEXT
  138. //
  139.  
  140. #pragma argsused
  141. LRESULT MsgNotify(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
  142. {
  143.     LPTOOLTIPTEXT lpToolTipText;
  144.     static char   szBuffer[64];
  145.  
  146.     lpToolTipText = (LPTOOLTIPTEXT)lparam;
  147.     if (lpToolTipText->hdr.code == TTN_NEEDTEXT)
  148.     {
  149.         LoadString(hInst,
  150.                    lpToolTipText->hdr.idFrom,   // string ID == command ID
  151.                    szBuffer,
  152.                          sizeof(szBuffer));
  153.  
  154.         lpToolTipText->lpszText = szBuffer;
  155.     }
  156.     return 0;
  157. }
  158.